import Vue from 'vue';
import viewImg from './index.vue';

let ViewImgConstructor = Vue.extend(viewImg);
let instance;

const ViewImg = function (options = {}) {
  instance = new ViewImgConstructor({
    el: document.createElement('div'),
    data: options,
  }).$mount();
  document.body.appendChild(instance.$el);
  instance.content = options;
};

const open = function (options={}) {
  if(!options.viewSrc) {
    console.error('img is not find');
    return;
  }
  ViewImg(options);
};

const close = function () {
  if (instance) {
    instance.close();
  }
};

export default {
  open,
  close
};
